package im.yisme.view.ui.component;

import im.yisme.view.ui.util.PointChecker;
import android.graphics.Bitmap;
import android.graphics.PointF;

public class YButton extends YComponent implements Clickable{


	private int status;	
	private OnClickListener listener;
	
	public static final int RELEASED=0;
	public static final int PRESSED=1;
	
	private Bitmap bgp_pressed,bgp_released;
	
	public YButton(){
		isVisible=true;
		status=RELEASED;
	}

	public boolean isTouched(float x,float y){
		if (points != null)
			return isTouchedForUnregular(x, y);
		
		if(x>this.x && x<this.x+width && y>this.y && y<this.y+height) return true;
		else return false;
	}
	
	private boolean isTouchedForUnregular(float x,float y){
		return PointChecker.isInside(points, new PointF(x, y));
	}
	
	public void click(){
		listener.OnClick();
	}
	public void setBounds(float x,float y,int width,int height){
		this.x=x;
		this.y=y;
		this.width=width;
		this.height=height;
	}

    public void press(){
    	status=PRESSED;
    }
    public void release(){
    	status=RELEASED;
    }
    public int getStatus(){
    	return status;
    }

	public void setOnClickListener(OnClickListener listener) {
		// TODO Auto-generated method stub
		this.listener=listener;
	}

	public void setBgp_pressed(Bitmap bgp_pressed) {
		this.bgp_pressed = bgp_pressed;
	}

	public Bitmap getBGP() {
		if(status == PRESSED){
			return bgp_pressed;
		}
		else {
			return bgp_released;
		}
		
	}

	public void setBgp_released(Bitmap bgp_released) {
		this.bgp_released = bgp_released;
	}
}
